<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- Use IE8 mode -->
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8 charset={$charset}" />
    <meta http-equiv="Content-Type" content="text/html; charset={$charset}" />
    <title> {$lang.index} </title>
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        //<!CDATA[
        var SITE_URL = "{$site_url}";
        var REAL_SITE_URL = "{$real_site_url}";
        var REAL_BACKEND_URL = "{$real_backend_url}";
        //]]>
    </script>
    <script src="templates/js/jquery.js"></script>
    <script type="text/javascript" src="{lib file=ecmall.js}" charset="utf-8"></script>
    <script type="text/javascript" src="{res file=js/admin.js}" charset="utf-8"></script>
    <script type="text/javascript" src="{res file=js/jslang.js}"></script>
    {$_head_tags}
</head>
<body>
<script type="text/javascript">
    $(function () {
        $('#ad_form').validate({
            errorPlacement: function (error, element) {
                $(element).next('.field_notice').hide();
                $(element).after(error);
            },
            success: function (label) {
                label.addClass('right').text('OK!');
            },
            onkeyup: false,
            rules: {
                {if !$ad.ad_pic}
                ad_pic: {
                    required: true,
                    accept: 'gif|png|jpe?g'
                },
                {/if}
                ad_name: {
                    required: true,
                }
            },
            messages: {
                {if !$ad.ad_pic}
                ad_pic: {
                    required: '{$lang.ad_logo_empty}',
                    accept: '{$lang.limit_img}'
                },
                {/if}
                ad_name: {
                    required: '{$lang.ad_name_empty}',
                }
            }
        });
    });
</script>
<div id="rightTop">
    <p>{$lang.ad}</p>
    <ul class="subnav">
        <li><a class="btn1" href="index.php?app=coupon_codes">{$lang.manage}</a></li>
        <li><span>{$lang.edit}</span></li>
    </ul>
</div>

<div class="info">
    <form method="post" enctype="multipart/form-data" id="recommend_form">
        <table class="infoTable">
            <tr>
                <th class="paddingT15">
                    选择折扣仓库:</th>
                <td class="paddingT15 wordSpacing5" >
                    <!--{foreach from=$storeStock item=store}-->

                    <label>
                        <input type="checkbox" name="storestock_id[]"  value="{$store.storestock_id}" {$store.checked}>
                            {$store.stock_name}
                    </label>
                    <!--{/foreach}-->
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    折扣值:
                </th>
                <td class="paddingT15 wordSpacing5" >
                    <input type="text" name="value" value="{$find_data.value}">
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    {$lang.choose_goods}:</th>
                <td class="paddingT15 wordSpacing5">
                    <button class="formbtn cart-add" type="button">{$lang.choose}</button>
                    <div class="choose_goods" style="padding-top:20px ">
                        <tr class="tatr1" id="after">
                            <td width="30%"><span  fieldname="goods_name">{$lang.goods_name}</span></td>
                            <td><span  fieldname="total_inventory">{$lang.total_inventory}</span></td>
                            <td><span  fieldname="default_image">{$lang.default_image}</span></td>
                            <td width="30%"><span  fieldname="views">{$lang.views}</span></td>
                        </tr>

                        <!--{foreach from=$banner.goods item=bg}-->
                            <tr class="tatr1">
                                <td class="table-center">
                                    <label class="goods_name" style="padding: 5px; border:1px solid #e3e3e3 ;" name="goods" value="{$bg.goods_id}">{$bg.goods_name}</label>
                                </td>
                                <td class="table-center">
                                    <label style="padding: 5px; border:1px solid #e3e3e3 ;" name="goods" value="{$bg.goods_id}">{$bg.total_inventory}</label>
                                </td>
                                <td class="table-center"><img  height="80" src="{$bg.default_image}" /></td>
                                <td class="table-center">
                                    <a href="javascript:;" class="findLayer" data-goodsId="{$bg.goods_id}">查看规格信息</a>   |
                                    <input type="checkbox" checked style="display: none" value="{$bg.goods_id}" name="goods"><img style="margin-right: 10px;width:15px;height: 15px;" src="templates/style/images/close.gif" onclick="dropGoods(this)" fieldname="mall_recommended" fieldid="{$bg.goods_id}" fieldvalue="1" title="{$lang.editable}"/>
                                </td>
                            </tr>

                        <!--{/foreach}-->
                    <input id="goods_id" name="goods_id" style="display: none" value="{$banner.goods_id}">
                    <input id="spec_id" name="spec_id" style="display: none" value="{$banner.spec_id}">
                </td>
            </tr>
            <tr>
                <th></th>
                <td class="ptb20">
                    <input class="formbtn" type="submit" name="Submit" value="{$lang.submit}" />
                    <input class="formbtn" type="reset" name="Submit2" value="{$lang.reset}" />
                </td>
            </tr>
        </table>
    </form>

    <div class = "bg-model" style="position:absolute;top:0%;left:0%;display:none;background:rgba(0,0,0,0.3);width:100%;height:100%;position:fixed;z-index:9999">
        <iframe src="index.php?app=goods&act=iframe&type=coupon_codes&id={$find_data.id}" id="goods_page" width="90%" height="90%"></iframe>
    </div>
<input type="hidden" name="discountValue" value="{$find_data.value}">
</div>
{include file="footer.html"}
<script src="templates/js/layer/layer.js"></script>
<script>


    var goods_id = '';
    $(function () {


    })
    $(".cart-add").click(function () {
        $("iframe").contents().find(".checkitem:checked");
        $("iframe").contents().find(".checkitem:checked").each(function () {
            $(this).removeAttr('checked');
        })
        $("iframe").contents().items = '';
        $(".bg-model").fadeTo(300,1)
        //隐藏窗体的滚动条
        $("body").css({ "overflow": "hidden" });
    });

    //模态框OK按钮点击事件
    $(".bg-model-ok").click(function () {
        $(".bg-model").hide();
        //显示窗体的滚动条
        $("body").css({ "overflow": "visible" });
    }).hover(function () {
        $(this).css({ "backgroundColor": "#8CC8C8" });
    }, function () {
        $(this).css({ "backgroundColor": "#8CD4E6" });
    });
    $("#enter").click(function () {
        var items = '';
        var name = '';
        $('.checkitem:checked').each(function(){
            items += this.value + ',';
            name += $(this).attr('attr-name') + ','
        });
        items = items.substr(0, (items.length - 1));
        name = name.substr(0, (name.length - 1));
        var items_arr = items.split(',');
        var name_arr = name.split(',');
        for(var i in items_arr){
            $(".choose_goods").append('<label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+name_arr[i]+'</label><input type="checkbox" checked style="display: none" value="'+items_arr[i]+'" name="goods"><a href="javascript:;" class="findLayer" data-goodsId="'+items_arr[i]+'">查看规格信息</a>   |\n<img style="margin-right: 10px;width:15px;height: 15px;" src="templates/style/images/close.gif" onclick="dropGoods(this' +
                ')" fieldname="mall_recommended" fieldid="{$goods.goods_id}" fieldvalue="1" title="{$lang.editable}"/>');
        }
        $('#goods_id').val($('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','));
        $(".bg-model").hide();
        //显示窗体的滚动条
        $("body").css({ "overflow": "visible" });
    })

    $(document).on('click','.findLayer',function(){
        var goodsId = $(this).attr('data-goodsId');
        var url = "index.php?app=coupon_codes&act=goodsSpecInfo";
        var str = '<table class="infoTable"><tr class="paddingT15">' +
            '<td class="paddingT15 wordSpacing5">规格id</td>' +
            '<td class="paddingT15 wordSpacing5">规格信息</td>' +
            '<td class="paddingT15 wordSpacing5">商品价格</td>' +
            '<td class="paddingT15 wordSpacing5">商品库存</td>' +
            '<td class="paddingT15 wordSpacing5">商品仓库</td>' +
            '<td class="paddingT15 wordSpacing5">当前折扣</td>' +
            '<td class="paddingT15 wordSpacing5">折扣后价格</td>' +
            '</tr>';
        var discountValue = $("input[name=discountValue]").val();
        $.post(url,{
            goods_id: goodsId
        },function(data){
            var res = JSON.parse(data);
            if(res.code == 1){
                var dataArr = res.msg;
                var price = 0;
                $.each(dataArr,function(index,item){
                    if(!item.spec_3){
                        item.spec_3 = '无';
                    }
                    price = item.discount_price;
                    if(item.price == 0){
                        price = 0;
                    }
                    var series ={$find_dataStoreStock};

                    if(!isInArray(series,item.spec_3value)){
                        discountValue = '无折扣';
                        price = item.price;
                    }
                    str += '<tr>' +
                        '<td class="paddingT15 wordSpacing5">'+item.spec_id+'</td>' +
                        '<td class="paddingT15 wordSpacing5">'+item.spec_1value+''+item.spec_2+'</td>' +
                        '<td class="paddingT15 wordSpacing5">'+item.price+'</td>' +
                        '<td class="paddingT15 wordSpacing5">'+item.stock+'</td>' +
                        '<td class="paddingT15 wordSpacing5">'+item.spec_3+'</td>' +
                        '<td class="paddingT15 wordSpacing5">'+discountValue+'</td>' +
                        '<td class="paddingT15 wordSpacing5">'+price+'</td>' +
                        '</tr>';

                })
                str += '</table>';
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['700px', '400px'], //宽高
                    content: str
                });

    }else{
                layer.msg(res.msg);
            }
        })


    })

    function isInArray(arr,value){
        for(var i = 0; i < arr.length; i++){
            if(value === arr[i]){
                return true;
            }
        }
        return false;
    }

    function dropGoods(obj) {
        $(obj).parent().parent().remove();
        $(obj).remove()
        $('#goods_id').val($('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','));
    }

</script>
